#include <iostream>
#include <math.h>

using namespace std;

long long int solvek(long long int num)
{
    float n = num;

    return ceil((-1+sqrt(1 + 8*n))/2);
}

long long int solvej(long long int n, long long int k)
{
    return n - ((k-1)*k)/2;
}

long long int sumn(long long int e)
{
    return (1+e)*e/2;
}

long long int sums(long long int n)
{
    return n*(n+1)*(2*n+1)/6;
}

long long int solve(long long int n)
{
    long long int k = solvek(n);
    long long int j = solvej(n, k);

    return (sums(k-1)+sumn(k-1))/2 +  sumn(j);

}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        long long int l, r;
        cin>>l>>r;
        cout<<solve(r)-solve(l-1)<<endl;
    }
    return 0;
}
